home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BoundedRangeModel.java < prev    next >
Text File  |  1998-06-30  |  8KB  |  248 lines

  1. /*
  2.  * @(#)BoundedRangeModel.java    1.16 98/02/26
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing;
  22.  
  23. import com.sun.java.swing.event.*;
  24.  
  25.  
  26. /**
  27.  * Defines the data model used by components like Sliders and ProgressBars.
  28.  * Defines four interrelated integer properties: minimum, maximum, extent
  29.  * and value.  These four integers define two nested ranges like this:
  30.  * <pre>
  31.  * minimum <= value <= value+extent <= maximum
  32.  * </pre>
  33.  * The outer range is <code>minimum,maximum</code> and the inner
  34.  * range is <code>value,value+extent</code>.  The inner range
  35.  * must lie within the outer one, i.e. <code>value</code> must be 
  36.  * less than or equal to <code>maximum</code> and <code>value+extent</code>
  37.  * must greater than or equal to <code>minimum</code>, and <code>maximum</code>
  38.  * must be greater than or equal to <code>minimum</code>.
  39.  * There are a few features of this model that one might find a little 
  40.  * surprising.  These quirks exist for the convenience of the
  41.  * Swing BoundedRangeModel clients like like  Slider and ScrollBar.
  42.  * <ul>
  43.  * <li> 
  44.  *   The minimum and maximum set methods "correct" the other 
  45.  *   three properties to acommodate their new value argument.  For 
  46.  *   example setting the model's minimum may change its maximum, value,
  47.  *   and extent properties (in that order), to maintain the constraints
  48.  *   specified above.  
  49.  * 
  50.  * <li>
  51.  *   The value and extent set methods "correct" their argument to 
  52.  *   fit within the limits defined by the other three properties.  
  53.  *   For example if <code>value == maximum</code>, <code>setExtent(10)</code>
  54.  *   would change the extent (back) to zero.
  55.  * 
  56.  * <li> 
  57.  *   The four BoundedRangeModel values are defined as Java Beans properties
  58.  *   however Swing ChangeEvents are used to notify clients of changes rather
  59.  *   than PropertyChangeEvents.  This was done to keep the overhead of monitoring
  60.  *   a BoundedRangeModel low.  Changes are often reported at MouseDragged rates. 
  61.  * </ul>
  62.  * 
  63.  * @version 1.16 02/26/98
  64.  * @author Hans Muller
  65.  * @see DefaultBoundedRangeModel
  66.  */
  67. public interface BoundedRangeModel
  68. {
  69.     /**
  70.      * Returns the minimum acceptable value.
  71.      *
  72.      * @return the value of the minimum property
  73.      * @see #setMinimum
  74.      */
  75.     int getMinimum();
  76.  
  77.  
  78.     /**
  79.      * Sets the model's minimum to <I>newMinimum</I>.   The 
  80.      * other three properties may be changed as well, to ensure 
  81.      * that:
  82.      * <pre>
  83.      * minimum <= value <= value+extent <= maximum
  84.      * </pre>
  85.      * <p>
  86.      * Notifies any listeners if the model changes.
  87.      *
  88.      * @param newMinimum the model's new minimum
  89.      * @see #getMinimum
  90.      * @see #addChangeListener
  91.      */
  92.     void setMinimum(int newMinimum);
  93.  
  94.  
  95.     /**
  96.      * Returns the model's maximum.  Note that the upper
  97.      * limit on the model's value is (maximum - extent).
  98.      *
  99.      * @return the value of the maximum property.
  100.      * @see #setMaximum
  101.      * @see #setExtent
  102.      */
  103.     int getMaximum();
  104.  
  105.  
  106.     /**
  107.      * Sets the model's maximum to <I>newMaximum</I>. The other 
  108.      * three properties may be changed as well, to ensure that
  109.      * <pre>
  110.      * minimum <= value <= value+extent <= maximum
  111.      * </pre>
  112.      * <p>
  113.      * Notifies any listeners if the model changes.
  114.      *
  115.      * @param newMaximum the model's new maximum
  116.      * @see #getMaximum
  117.      * @see #addChangeListener
  118.      */
  119.     void setMaximum(int newMaximum);
  120.  
  121.  
  122.     /**
  123.      * Returns the model's current value.  Note that the upper
  124.      * limit on the model's value is <code>maximum - extent</code> 
  125.      * and the lower limit is <code>minimum</code>.
  126.      *
  127.      * @return  the model's value
  128.      * @see     #setValue
  129.      */
  130.     int getValue();
  131.  
  132.  
  133.     /**
  134.      * Sets the model's current value to <code>newValue</code> if <code>newValue</code>
  135.      * satisfies the model's constraints. Those constraints are:
  136.      * <pre>
  137.      * minimum <= value <= value+extent <= maximum
  138.      * </pre>
  139.      * Otherwise, if <code>newValue</code> is less than <code>minimum</code> 
  140.      * it's set to <code>minimum</code>, if its greater than 
  141.      * <code>maximum</code> then it's set to <code>maximum</code>, and 
  142.      * if it's greater than <code>value+extent</code> then it's set to 
  143.      * <code>value+extent</code>.
  144.      * <p>
  145.      * When a BoundedRange model is used with a scrollbar the value
  146.      * specifies the origin of the scrollbar knob (aka the "thumb" or
  147.      * "elevator").  The value usually represents the origin of the 
  148.      * visible part of the object being scrolled.
  149.      * <p>
  150.      * Notifies any listeners if the model changes.
  151.      *
  152.      * @param newValue the model's new value
  153.      * @see #getValue
  154.      */
  155.     void setValue(int newValue);
  156.  
  157.  
  158.     /**
  159.      * This attribute indicates that any upcoming changes to the value
  160.      * of the model should be considered a single event. This attribute
  161.      * will be set to true at the start of a series of changes to the value,
  162.      * and will be set to false when the value has finished changing.  Normally
  163.      * this allows a listener to only take action when the final value change in
  164.      * committed, instead of having to do updates for all intermediate values.
  165.      * <p>
  166.      * Sliders and scrollbars use this property when a drag is underway.
  167.      * 
  168.      * @param b true if the upcoming changes to the value property are part of a series
  169.      * @see #getValueIsAdjusting
  170.      */
  171.     void setValueIsAdjusting(boolean b);
  172.  
  173.  
  174.     /**
  175.      * Returns true if the current changes to the value property are part 
  176.      * of a series.
  177.      * 
  178.      * @return the valueIsAdjustingProperty.  
  179.      * @see #setValueIsAdjusting
  180.      */
  181.     boolean getValueIsAdjusting();
  182.  
  183.  
  184.     /**
  185.      * Returns the model's extent, the length of the inner range that
  186.      * begins at the model's value.  
  187.      *
  188.      * @return  the value of the model's extent property
  189.      * @see     #setExtent
  190.      * @see     #setValue
  191.      */
  192.     int getExtent();
  193.  
  194.  
  195.     /**
  196.      * Sets the model's extent.  The <I>newExtent</I> is forced to 
  197.      * be greater than or equal to zero and less than or equal to
  198.      * maximum - value.   
  199.      * <p>
  200.      * When a BoundedRange model is used with a scrollbar the extent
  201.      * defines the length of the scrollbar knob (aka the "thumb" or
  202.      * "elevator").  The extent usually represents how much of the 
  203.      * object being scrolled is visible.  
  204.      * <p>
  205.      * Notifies any listeners if the model changes.
  206.      *
  207.      * @param  newExtent the model's new extent
  208.      * @see #getExtent
  209.      * @see #setValue
  210.      */
  211.     void setExtent(int newExtent);
  212.  
  213.  
  214.  
  215.     /**
  216.      * This method sets all of the model's data with a single method call.
  217.      * The method results in a single change event being generated. This is
  218.      * convenient when you need to adjust all the model data simulaneously and
  219.      * do not want individual change events to occur.
  220.      * 
  221.      * @see #setValue
  222.      * @see #setExtent
  223.      * @see #setMinimum
  224.      * @see #setMaximum
  225.      * @see #setValueIsAdjusting
  226.      */
  227.     void setRangeProperties(int value, int extent, int min, int max, boolean adjusting);
  228.  
  229.  
  230.     /**
  231.      * Adds a ChangeListener to the model's listener list.
  232.      *
  233.      * @param x the ChangeListener to add
  234.      * @see #removeChangeListener
  235.      */
  236.     void addChangeListener(ChangeListener x);
  237.  
  238.  
  239.     /**
  240.      * Removes a ChangeListener from the model's listener list.
  241.      *
  242.      * @param x the ChangeListener to remove
  243.      * @see #addChangeListener
  244.      */
  245.     void removeChangeListener(ChangeListener x);
  246.  
  247. }
  248.